package com.eckey.lab.controller;

import com.eckey.lab.config.FreshProperties;
import com.eckey.lab.feign.UserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
//@RefreshScope
@RestController
@RequestMapping("/order")
public class OrderController {

    @Value("${thread.num}")
    private Integer threadNum;

    @Autowired
    private FreshProperties properties;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserFeign userFeign;

    @GetMapping("/test")
    public String getUserById(@RequestHeader(value = "hello", required = false) String value) {
        System.out.println("value:" + value);
        String url = "http://userservice/user/findOrderByUserId/";
        String forObject = restTemplate.getForObject(url, String.class);
        log.info("查询结果为：{}", forObject);
        return forObject;
    }

    @GetMapping()
    public Integer get() {
        return properties.getNum();
    }

    @GetMapping("/feign")
    public String getUserById() {
        String userById = userFeign.getUserById();
        return userById;
    }

}
